<?php

namespace App\Http\Requests\Backend;

use Illuminate\Foundation\Http\FormRequest;

class ArticleRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = [
            'title' => ['bail','required','max:255'],
            'category_id' => ['bail', 'required'],
            'tags' => ['bail', 'required'],
        ];

        if ($this->isMethod('post')) {
            $rules['title'] = array_merge($rules['title'], ['unique:articles']);
        }

        return $rules;
    }
    public function messages()
    {
        return [
            'title.required' => '请输入标题',
            'title.max' => '姓名长度不能超过255个字符',
            'category_id.required' => '分类不能为空',
            'tags.required' => 'tag不能为空',
        ];
    }
}
